package com.controller;

import com.until.JarUtil;

import java.io.File;

/**
 * @ Author xsd
 * @ crate time 2020/5/26 11:50
 * @ 描述
 */
public class FileHandle {
    public static void main(String[] args) throws Exception {
        File file = new File("C:\\Users\\qinjian\\Desktop\\settle-");
        //统一解压-
        press(file);
    }
    public static void press(File file){
        File[] files = file.listFiles();
        for (File f : files) {
            if (f.isFile()) {
                String path = f.getPath();
                if (path.endsWith(".jar")) {
                    System.out.println("解压文件为：" + path);
                    String out = path.replace(".jar", "");
                    //解压-
                    JarUtil.decompress(path, out);
                    //删除解压文件
                    JarUtil.deleteRecursively(path);
                    func(new File(out));
                    //压缩 大包
                    JarUtil.zip(out, path.replace(".jar","-settle.jar"), JarUtil.CompressType.JAR);
                    //解压
                    JarUtil.deleteRecursively(out);
                    System.out.println("打包文件为：" + path);

                }
            }
        }
    }
    private static void func(File file) {
        File[] files = file.listFiles();
        for (File f : files) {
            //若是目录，则递归打印该目录下的文件
            if (f.isDirectory()) {
                func(f);
            }
            //若是文件，直接打印
            if (f.isFile()) {
                String path = f.getPath();
                if (path.endsWith(".jar")) {
                    System.out.println("解压文件为：" + path);
                    String out = path.replace(".jar", "");
                    //解压-
                    JarUtil.decompress(path, out);
                    //写入文件
                    JarUtil.writeFile(out + File.separator + "start.sh");
                    //删除jar
                    JarUtil.deleteRecursively(path);
                    //压缩
                    JarUtil.zip(out, path.replace(".jar","-settle.jar"), JarUtil.CompressType.JAR);
                    //删除解压文件
                    JarUtil.deleteRecursively(out);
                    System.out.println("打包文件为：" + path);
                }
            }
        }
    }
}
